<template>
  <van-action-sheet v-model:show="menuShow" cancel-text="取消" @close="$emit('cancel_show')">
    <a :href="`tel:${telNumber}`" @click="countContactAdd">
      <div class="content">
        拨打电话:&nbsp;&nbsp;
        <span>{{ telNumber }}</span>
      </div>
    </a>
  </van-action-sheet>
</template>

<script lang="ts">
import { defineComponent, ref, reactive, toRefs, watchEffect } from 'vue'
import { api } from '@/http/api'
import http from '@/http'

export default defineComponent({
  name: '',
  props: {
    isShow: {
      type: Boolean,
      default: false
    }, //是否弹框显示
    telNumber: {
      type: [String, Number],
      default: ''
    }, //电话号码
    orderId: {
      type: String,
      default: ''
    },
    isCountContact: {
      type: Boolean,
      default: false
    }
  },
  emits: ['cancel_show'],
  setup(props, ctx) {
    const menuShow = ref<boolean>(false)

    watchEffect(() => {
      menuShow.value = props.isShow
    })

    const countContactAdd = () => {
      if (props.isCountContact) {
        http<string>({
          url: api.countContact,
          method: 'post',
          data: { orderId: props.orderId }
        })
      }
    }

    return {
      menuShow,
      countContactAdd
    }
  }
})
</script>
<style lang="scss" scoped>
@import '@/style/variables.scss';
.content {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  span {
    color: $color-primary;
  }
}
</style>
